using System;
using System.Collections.Generic;
using System.Text;

namespace Weazel.Microblaze.Simulator.Components.Microblaze.Instructions
{
    /// <summary>
    /// Immediate
    /// </summary>
    public class Imm : Instruction
    {

        public override int CycleCount
        {
            get { return 1; }
        }

        public Imm()
            : base("imm")
        {
        }

        /// <summary>
        /// The instruction imm loads the IMM value into a temporary register. 
        /// It also locks this value so it can be used by the following 
        /// instruction and form a 32-bit immediate value. The instruction imm 
        /// is used in conjunction with Type B instructions. Since Type B 
        /// instructions have only a 16-bit immediate value field, a 32-bit 
        /// immediate value cannot be used directly. However, 32-bit immediate 
        /// values can be used in MicroBlaze. By default, Type B Instructions 
        /// will take the 16-bit IMM field value and sign extend it to 32 bits 
        /// to use as the immediate operand. This behavior can be overridden by 
        /// preceding the Type B instruction with an imm instruction. The imm 
        /// instruction locks the 16-bit IMM value temporarily for the next 
        /// instruction. A Type B instruction that immediately follows the imm 
        /// instruction will then form a 32-bit immediate value from the 16-bit 
        /// IMM value of the imm instruction (upper 16 bits) and its own 16-bit 
        /// immediate value field (lower 16 bits). If no Type B instruction 
        /// follows the IMM instruction, the locked value gets unlocked and 
        /// becomes useless.
        /// </summary>
        /// <param name="MicroblazeComponent"></param>
        public override void Execute(MicroblazeComponent MicroblazeComponent)
        {
            MicroblazeComponent.ImmediateValue = ImmediateValue;
            MicroblazeComponent.ImmediateValueSet = true;
        }

        public override string ToString()
        {
            return string.Format("imm {0}", ImmediateValue);
        }
    }
}
